<?php
namespace app\controller;
use app\BaseController;
use think\facade\Request;
use think\facade\Db;
use think\facade\View;


class Other extends BaseController
{
    #substr函数
    public function demo_substr(){
        return View::fetch();
    }

    #伊布
    public function demo_yibu(){
        return View::fetch();
    }

    #雷达
    public function demo_leida(){
        return View::fetch();
    }

    #动画404
    public function demo_action404(){
        return View::fetch();
    }

    #执子之手与子皆老
    public function demo_aq(){
        return View::fetch('blog_aq');
    }

    #音乐播放插件
    public function sim_music(){
        return View::fetch();
    }




	######################################################################################################################
	# 一些废弃的方法
    ######################################################################################################################

    # 获取用户信息 不准确 不好使
    # 设备信息 小米note2
    # 系统信息 Win10 WinXP MacOsX
    # 浏览器信息 Firefox Chrome Edge
    protected function get_request()
    {
        require_once '../extend/common/request.php';
        if($this->request->isMobile())
            $is_mobile = get_mobile($this->request->header('user-agent'));
        else
            $is_mobile = null;
        $data = [
            'os'         => get_os(),
            'broswer'    => get_broswer(),
            'is_mobile'  => $is_mobile,
        ];
        return $data;
    }

    /**
     * 淘宝网IP地址公共API 不稳定 不好使
     * @param  IP地址
     * @return array('country','region','city','isp')
     */
    protected function get_ip_taobao($ip)
    {
        header("Content-type:text/html;charset=utf-8");
        function GetCurl($url){
            $curl = curl_init();
            curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
            curl_setopt($curl,CURLOPT_URL, $url);
            curl_setopt($curl,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
            $resp = curl_exec($curl);
            curl_close($curl);
            return $resp;
        }
        $resip = GetCurl("http://ip.taobao.com/service/getIpInfo.php?ip=".$ip);
        $resip = json_decode($resip,true);
        if(!empty($resip) && $resip['code']==0){
            $res = $resip['data'];
            return [$res['country'],$res['region'],$res['city'],$res['isp']];
        }else{
            return false;
        }
    }

    # 重新登录
    public function re_login(){
        $uid  = Session::get('user.uid');
        if($uid){
            $user = Db::name('user')->where('uid',$uid)->findOrEmpty();
            Session::set('user', $user);
            $this->error('重新登录成功','/index/blog','',1);
        }else{
            $this->error('您本身就未登录','/index/blog','',1);
        }
    }

    public function get_json_joke(){
        header("Content-type:text/html;charset=utf-8");
        function GetCurl($url){
            $curl = curl_init();
            curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
            curl_setopt($curl,CURLOPT_URL, $url);
            curl_setopt($curl,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
            $resp = curl_exec($curl);
            curl_close($curl);
            return $resp;
        }
        $resp = GetCurl("http://www.kuitao8.com/api/joke");
        $resp = json_decode($resp,true);
        return $resp['content'];
    }


}
